<template>
  <!--资金管理首页-->
  <div>
    <common-title title-name="项目进展情况" />
    <div class="capital-budgeting-content d-flex j-sb">
      <public-card
        v-for="(n, i) in cardInfo.cardArr1"
        :key="i"
        :title="n.title"
        :url="n.url"
        :unit="n.unit"
        :num="n.num"
        get-width="350px"
        icon-type="svg"
      ></public-card>
    </div>
    <common-title title-name="项目资金概况" />
    <div class="implementation-content d-flex">
      <public-card
        class="m-r50"
        v-for="(n, i) in cardInfo.cardArr2"
        :key="i"
        :title="n.title"
        :url="n.url"
        :unit="n.unit"
        :num="n.num"
        get-width="350px"
        icon-type="svg"
      ></public-card>
    </div>
    <common-title class="m-t20" title-name="项目质量监督" />
    <div class="financing-content d-flex">
      <public-card
        class="m-r50"
        v-for="(n, i) in cardInfo.cardArr3"
        :key="i"
        :title="n.title"
        :url="n.url"
        :unit="n.unit"
        :num="n.num"
        get-width="350px"
        icon-type="svg"
      ></public-card>
    </div>
    <common-title class="m-t20" title-name="项目阶段" />
    <div class="financing-content d-flex">
      <public-card
        class="m-r50"
        v-for="(n, i) in cardInfo.cardArr4"
        :key="i"
        :title="n.title"
        :url="n.url"
        :unit="n.unit"
        :num="n.num"
        get-width="350px"
        icon-type="svg"
      ></public-card>
    </div>
  </div>
</template>

<script setup>
import CommonTitle from '@/components/CommonTitle.vue'
import PublicStatistics from '@/components/PublicStatistics.vue'
import { onMounted, reactive } from 'vue'
import { financingApi, fundManagementApi } from '@/api/businessFinance'
import { useRouter } from 'vue-router'
import PublicCard from '@/components/uploadCom/public-card.vue'
import { systemApi } from '@/api/project'

const cardInfo = reactive({
  cardArr1: [
    {
      title: '工程建设项目(在建)',
      num: '',
      url: 'property-icon-6',
      unit: '个',
      iconType: 'svg'
    },
    {
      title: '工程建设项目(竣工)',
      num: '',
      url: 'property-icon-6',
      unit: '个',
      iconType: 'svg'
    },
    {
      title: '预备项目库数量',
      num: '',
      url: 'property-icon-6',
      unit: '个',
      iconType: 'svg'
    }
  ],
  cardArr2: [
    {
      title: '已完成投资/计划投资(万元)',
      num: '',
      url: 'property-icon-1',
      unit: '%',
      iconType: 'svg'
    },
    {
      title: '已支出总额/支出(万元)',
      num: '',
      url: 'property-icon-2',
      unit: '%',
      iconType: 'svg'
    }
  ],
  cardArr3: [
    {
      title: '待整改',
      num: '',
      url: 'property-icon-4',
      unit: '个',
      iconType: 'svg'
    },
    {
      title: '已整改',
      num: '',
      url: 'property-icon-5',
      unit: '个',
      iconType: 'svg'
    },
    {
      title: '待复检',
      num: '',
      url: 'property-icon-5',
      unit: '个',
      iconType: 'svg'
    },
    {
      title: '验收通过',
      num: '',
      url: 'property-icon-5',
      unit: '个',
      iconType: 'svg'
    }
  ],
  cardArr4: [
    {
      title: '未开工',
      num: '',
      url: 'property-icon-4',
      unit: '个',
      iconType: 'svg'
    },
    {
      title: '施工中',
      num: '',
      url: 'property-icon-5',
      unit: '个',
      iconType: 'svg'
    },
    {
      title: '已竣工',
      num: '',
      url: 'property-icon-5',
      unit: '个',
      iconType: 'svg'
    },
    {
      title: '停工',
      num: '',
      url: 'property-icon-5',
      unit: '个',
      iconType: 'svg'
    },
    {
      title: '其他',
      num: '',
      url: 'property-icon-5',
      unit: '个',
      iconType: 'svg'
    }
  ]
})
//获取项目数量统计
const getProjectCount = async () => {
  await systemApi.getProjectNum().then((res) => {
    if (res.code == '200') {
      
      const {
        allProjectCount,
        buildProjectCount,
        completeProjectCount,
        prepareProjectCount
      } = res.data
      // allProjectCount 全部数量
      // completeProjectCount 竣工数量
      // buildProjectCount 在建数量
      // prepareProjectCount 预备项目数量
      cardInfo.cardArr1[0].num = buildProjectCount
      cardInfo.cardArr1[1].num = completeProjectCount
      cardInfo.cardArr1[2].num = prepareProjectCount
    }
  })
}
//获取计划支出资金
const getPlanFund = async () => {
  await systemApi.getFundCount().then((res) => {
    if (res.code == '200') {
      const { completedFund, payFund, allPayFund, planFund } = res.data
      //       completedFund: '', //	已完成投资
      //   planFund: '', //计划投资
      //   payFund: '', //支出总额
      //   allPayFund: '' //支出
      cardInfo.cardArr2[0].num = completedFund + '/' + planFund
      cardInfo.cardArr2[1].num = payFund + '/' + allPayFund
    }
  })
}
//获取质量督办概括
const getQualitySupervision = async () => {
  await systemApi.getQualityCount().then((res) => {
    if (res.code == '200') {
      const { needReform, alreadyReform, needRecheck, passProject } = res.data
      // needReform 待整改
      // alreadyReform 已整改
      // needRecheck 待复检
      // passProject 验收通过
      cardInfo.cardArr3[0].num = needReform
      cardInfo.cardArr3[1].num = alreadyReform
      cardInfo.cardArr3[2].num = needRecheck
      cardInfo.cardArr3[3].num = passProject
    }
  })
}
//获取工程进度概括
const getStageCount = async () => {
  await systemApi.getStageCount().then((res) => {
    if (res.code == '200') {
      const { notWork, inProgress, other, stopWork, completed } = res.data
      // notWork 未开工
      // inProgress 施工中
      // other 其他
      // stopWork 停工
      // completed 已竣工
      cardInfo.cardArr4[0].num = notWork
      cardInfo.cardArr4[1].num = inProgress
      cardInfo.cardArr4[2].num = other
      cardInfo.cardArr4[3].num = stopWork
      cardInfo.cardArr4[4].num = completed
    }
  })
}
onMounted(() => {
  getProjectCount()
  getPlanFund()
  getQualitySupervision()
  getStageCount()
})
</script>

<style lang="scss" scoped>
.capital-budgeting-content {
  .bg-icon {
    width: 216px;
    height: 88px;
    cursor: pointer;
  }
}
</style>
